package com.shell.provider;

import java.util.HashMap;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.shell.bee.base.annotation.Logging;
import com.shell.bee.base.utils.JsonUtil;
import com.shell.bee.base.utils.StringUtil;
import com.shell.bee.entity.auth.AuthUser;
import com.shell.bee.mvc.controller.BaseController;
import com.shell.governor.modules.service.MsgTipService;

@Controller
public class MsgTipProvider extends BaseController {

	@Autowired
	private MsgTipService msgTipService;

	@RequestMapping({ "/getMsgTip" })
	@Logging(methods = "获取代办任务")
	@ResponseBody
	public Map<String, Object> msgTip(String key, String userId, String authUser) throws Exception {
		Map<String, Object> map = new HashMap<String, Object>();
		AuthUser user = null;
		if (StringUtil.notEmpty(authUser)) {
			user = (AuthUser) JsonUtil.fromJson(authUser, AuthUser.class);
		}
		if ((StringUtil.emptyAndNull(key)) || ("notReadedMsgCount".equals(key))) {
			map.put("notReadedMsgCount", Integer.valueOf(this.msgTipService.getNotReadedMsgCount(userId)));
		}
		if ((StringUtil.emptyAndNull(key)) || ("noticeCount".equals(key))) {
			map.put("noticeCount", Integer.valueOf(this.msgTipService.getNoticeCount()));
		}
		if ((StringUtil.emptyAndNull(key)) || ("user-first-apr".equals(key))) {
			map.put("user-first-apr", Integer.valueOf(this.msgTipService.getUserAprCount("0", user)));
		}
		if ((StringUtil.emptyAndNull(key)) || ("user-final-apr".equals(key))) {
			map.put("user-final-apr", Integer.valueOf(this.msgTipService.getUserAprCount("1", user)));
		}
		return map;
	}
}
